import httpUtils from "../httpRequest";
import {
  FileModel,
  MachineModel,
  OrderItem, ProjectModel,
  TeamModel, TimeOrderModel, UserListModel,

} from "./model";


//481c-b7d6-bc41028701ca
// /admin/captcha?uuid=8a8e9f1e-efa8
///admin/yckj/user/list
export async function userListApi(): Promise<UserListModel[] | null> {
  try {
    return await httpUtils.request("/yckj/user/list", "GET", {}, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function userByMobileApi(mobile): Promise<UserListModel | null> {
  try {
    return await httpUtils.request("/yckj/api/user/byMobile", "GET", {
      mobile: mobile
    }, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function loginApi(params): Promise<any> {
  try {
    return await httpUtils.request("/login", "POST", params, false, false, false);
  } catch (e) {
    return null;
  }
}


export async function teamJoinApi(userId): Promise<TeamModel[] | null> {
  try {
    return await httpUtils.request("/yckj/api/join/team/list", "GET", {
      userId: userId
    }, false, false, false);
  } catch (e) {
    return null;
  }
}


///yckj/machine/list
export async function machineList2Api(): Promise<MachineModel[] | null> {
  try {
    return await httpUtils.request("/yckj/api/machine/list", "GET", {}, false, false, false);
  } catch (e) {
    return null;
  }
}


////yckj/common/uploadFile
export async function uploadFileApi(filePath, type = 'user'): Promise<FileModel | null> {
  try {
    return await httpUtils.uploadFile("/common/uploadFile", filePath, 'file', {
      type: type
    }, false);
  } catch (e) {
    return null;
  }
}

////http://118.193.103.197:8080/admin/yckj/api/machine/project/list?machineId=2
export async function projectMachineListApi(machineId, hideLoading = false): Promise<ProjectModel[] | null> {
  try {
    return await httpUtils.request("/yckj/api/machine/project/list", "GET", {
      machineId: machineId
    }, false, false, hideLoading);
  } catch (e) {
    return null;
  }
}


export async function orderSignApi(signImage, orderId): Promise<any> {
  try {
    return await httpUtils.request("/order/sign", "POST", {
      signImage: signImage,
      orderId: orderId,
    }, false, true, false);
  } catch (e) {
    return null;
  }
}


export async function orderSaveApi(params): Promise<any> {
  try {
    return await httpUtils.request("/yckj/api/order/appoint", "POST", params, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function orderPayApi(params): Promise<any> {
  try {
    return await httpUtils.request("/order/save", "POST", params, false, false, false);
  } catch (e) {
    return null;
  }
}

///yckj/order/cancel
export async function orderCancelApi(id): Promise<any> {
  try {
    return await httpUtils.request("/order/cancel", "POST", {
      orderId: id
    }, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function orderTimeApi(machineId): Promise<any> {
  try {
    return await httpUtils.request("/yckj/api/order/time", "GET", {
      machineId: machineId
    }, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function orderListApi(status): Promise<OrderItem[] | null> {
  try {
    return await httpUtils.request("/order/list", "GET", {
      status: status,
    }, true, false, false);
  } catch (e) {
    return null;
  }
}

export async function orderInfoApi(id): Promise<OrderItem | null> {
  try {
    return await httpUtils.request("/yckj/api/order/info", "GET", {
      id: id,
    }, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function appoints(id): Promise<TimeOrderModel[] | null> {
  try {
    return await httpUtils.request("/yckj/api/order/appoints", "GET", {
      machineId: id,
    }, false, false, false);
  } catch (e) {
    return null;
  }
}

export async function orderListById(id): Promise<OrderItem[] | null> {
  try {
    return await httpUtils.request("/yckj/api/order/list", "GET", {
      machineId: id,
    }, true, false, false);
  } catch (e) {
    return null;
  }
}







